package com.lt.basic.project.admin.controller.sys;

import com.alibaba.fastjson2.JSONArray;
import com.lt.basic.project.application.service.admin.sys.ISysDeptService;
import com.lt.basic.project.common.aop.NotPower;
import com.lt.basic.project.common.core.AjaxResult;
import com.lt.basic.project.common.validator.annotation.IDMust;
import com.lt.basic.project.pojo.validate.commons.IdValidate;
import com.lt.basic.project.pojo.validate.admin.sys.SysDeptCreateValidate;
import com.lt.basic.project.pojo.validate.admin.sys.SysDeptSearchValidate;
import com.lt.basic.project.pojo.validate.admin.sys.SysDeptUpdateValidate;
import com.lt.basic.project.pojo.vo.admin.sys.SysDeptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统部门管理
 * @author LT
 */
@RestController
@RequestMapping("admin/sys/dept")
@Api(tags = "系统部门管理")
public class SysDeptController {

    @Resource
    ISysDeptService iSysDeptService;

    /**
     * 部门所有
     * @return
     */
    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="部门所有")
    public AjaxResult<List<SysDeptVo>> all() {
        List<SysDeptVo> list = iSysDeptService.all();
        return AjaxResult.success(list);
    }

    /**
     * 部门列表
     * @param searchValidate
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value="部门列表")
    public AjaxResult<JSONArray> list(@Validated SysDeptSearchValidate searchValidate) {
        JSONArray list = iSysDeptService.list(searchValidate);
        return AjaxResult.success(list);
    }

    /**
     * 部门详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value="部门详情")
    public AjaxResult<SysDeptVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        SysDeptVo vo = iSysDeptService.detail(id);
        return AjaxResult.success(vo);
    }

    /**
     * 部门新增
     * @param createValidate
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value="部门新增")
    public AjaxResult<Object> add(@Validated @RequestBody SysDeptCreateValidate createValidate) {
        iSysDeptService.add(createValidate);
        return AjaxResult.success();
    }

    /**
     * 部门编辑
     * @param updateValidate
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value="部门编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody SysDeptUpdateValidate updateValidate) {
        iSysDeptService.edit(updateValidate);
        return AjaxResult.success();
    }

    /**
     * 部门删除
     * @param idValidate
     * @return
     */
    @PostMapping("/del")
    @ApiOperation(value="部门删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iSysDeptService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
